<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8" />
		<title>新增</title>
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<include file="common/tag"/>
	</head>
	<link rel="stylesheet" href="/static/plugin/ace/css/chosen.css" />
	<script src="/static/plugin/ace/js/chosen.jquery.min.js"></script>
	<style>
		body{
			background-color:#fff
		}
		.yui_right{
			float: right;
			margin-bottom: 10px;
		}
		#container {
			width: 95%;
			height: 300px;
		}
	</style>
	<body >
	<div>
		<div class="widget-main">

			<button class="btn btn-primary yui_right" id="yui_save">
				<i class="icon-plus align-top bigger-125"></i>
				保存
			</button>

			<br>

			<input type="hidden" name="id" value="{$data.id}"/>

			<div>
				<label >标题</label>
				<input type="text" name="title" placeholder="标题" class="form-control" value="{$data.title}"/>
			</div>

			<br>

			<div>
				<label >副标题</label>
				<input type="text" name="sub_title" placeholder="副标题" class="form-control" value="{$data.sub_title}"/>
			</div>

			<br>

			<div>
				<label >分类标签</label>
				<select class="form-control" name="label">
					<foreach name="labels" item="l">
						<eq name="data.label" value="$l.name">
							<option value="{$l.code}" selected>{$l.name}</option>
							<else/>
							<option value="{$l.code}">{$l.name}</option>
						</eq>
					</foreach>
				</select>
			</div>

			<br>

			<div>
				<label >标注</label>
				<input type="text" name="tags" placeholder="标注" class="form-control" value="{$data.tags}"/>
			</div>

			<br>

			<div>
				<label >状态</label>
				<select class="form-control" name="status">
					<eq name="data.status" value="1">
						<option value="1" selected>开启</option>
						<option value="0">关闭</option>
						<else/>
						<option value="0" selected>关闭</option>
						<option value="1">开启</option>
					</eq>
				</select>
			</div>

			<br>

			<div>
				<label >正文</label>
				<textarea id="container" class="content">
					{:htmlspecialchars_decode($data['content'])}
				</textarea>
			</div>

		</div>
	</div>

	</body>
	<include file="common/ueditor"/>
	<script>
		$(function () {
            $(".chosen-select").chosen();

            ue.ready(function() {
                $("#edui1").css('width','100%');
                $("#edui1_iframeholder").css('width','100%');
            });

            $("#yui_save").on('click' , function(){
                var id=$("input[name='id']").val();
                var title=$("input[name='title']").val();
                var sub_title=$("input[name='sub_title']").val();
                var label=$("select[name='label']").val();
                var tags=$("input[name='tags']").val();
                var status=$("select[name='status']").val();
                var content=ue.getContent();
                if (ue.hasContents()){
					//ajax提交数据
                    $.post("/index.php/admin/article/article_edit",
                        {
                            id:id,
                            title:title,
                            sub_title:sub_title,
                            label:label,
                            tags:tags,
                            content:content,
                            status:status
                        },
                        function(data,status){
                            if (data['code']==1){
                                layer.open({
                                    title: '提示',
                                    content: '操作成功'
                                    ,yes: function(index, layero){
                                        window.parent.location.reload();
                                    },cancel: function(){
                                        window.parent.location.reload();
                                    }
                                });
                            }else{
                                layer.msg(data['text']);
                            }
                        }, "json"
                    );
				}else {
                    layer.msg("正文内容不能为空!",{time:1000})
				}
            });
        });
	</script>

</html>
